package onion.molingo2o.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import onion.molingo2o.R;
import onion.molingo2o.activity.service.MyServerDetailActivity;
import onion.molingo2o.activity.service.MyServerSettingActivity;
import onion.molingo2o.adapter.OnionAdapter;
import onion.molingo2o.bean.MyServer;

/**
 * Created by Administrator on 2015/11/10.
 */
public class ServerFragment extends Fragment {
    private OnionAdapter adapter;
    private List<MyServer> list=new ArrayList<>();
    private ListView listView;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_server_list, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        listView = (ListView) getView().findViewById(R.id.listview);
        // 获取设置contactlist
        getTest();
       getView().findViewById(R.id.iv_server_setting).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               startActivity(new Intent(getActivity(), MyServerSettingActivity.class));
           }
       });
        // 设置adapter
        adapter = new OnionAdapter(getActivity(),R.layout.item_myserver_index,list,new String[]{"title","num"},new String[]{"getIcon"});
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), MyServerDetailActivity.class);
                startActivity(intent);
            }
        });
    }

    private void getTest() {
        for(int i=0;i<4;i++){
            list.add(new MyServer("http://img0.imgtn.bdimg.com/it/u=1237455343,3383829147&fm=21&gp=0.jpg","融资","3"));
        }
    }



}
